<%@ page import="custom.*, java.util.*" %>

<html>
  <head>
    <title>Provide degrees- Choose location</title>
  </head>
 <%
 	// retreive the information from the session attributes from the pages before
	String firstName = (String)session.getAttribute("firstName");
    String middleName = (String)session.getAttribute("middleName");
    String lastName = (String)session.getAttribute("lastName");
 	int ccid = (Integer)session.getAttribute("ccid");
   	int crid = (Integer)session.getAttribute("crid");
   	Vector countries = support.getCountries();

   	// if an session attribute returns null, that means the applicant has just entered the related information from the last page, and we should get it from the request parameter.
   	String street = (String)session.getAttribute("street");
   	if(street == null) {
   		street = request.getParameter("street");
   	 	session.setAttribute("street", street);
   	}
   	String city = (String)session.getAttribute("city");
   	if(city == null) {
   		city = request.getParameter("city");
   		session.setAttribute("city", city);
   	}
	String state = (String)session.getAttribute("state");
	if(state == null) {
		state = request.getParameter("state");
        if(state == null) session.setAttribute("state", "");
   		else session.setAttribute("state", state);
   	}
	String ctc = (String)session.getAttribute("ctc");
	if(ctc == null) {
		ctc = request.getParameter("ctc");
   		if(ctc == null) session.setAttribute("ctc", "0");
        else session.setAttribute("ctc", ctc);
   	}
	String zip = (String)session.getAttribute("zip");
	if(zip == null) {
		zip = request.getParameter("zip");
   		session.setAttribute("zip", zip);
   	}
	String area = (String)session.getAttribute("area");
	if(area == null) {
		area = request.getParameter("area");
   		session.setAttribute("area", area);
   	}

	String phone = (String)session.getAttribute("phone");
	if(phone == null) {
		phone = request.getParameter("phone");
   		session.setAttribute("phone", phone);
   	}

    Vector uniTuple = support.getUniversities();
    Vector majors = support.getMajors();
 %>
  <body>

    First Name: <%= firstName %>
    <br>
    Middle Initial: <%= middleName %>
    <br>
    Last Name: <%= lastName %>
    <br>
    Country of citizenship: <%= countries.get(ccid) %>
    <br>
    Country of residence: <%= countries.get(crid) %>
    <br>
    Street: <%= street %>
    <br>
    City: <%= city %>
    <br>
    <!-- if country of residnece is US, display state, else display country telephone code -->
    <% if(crid==support.us_id) { %>
    State: <%= state %>
    <% } else { %>
    Country telephone code: <%= ctc %>
    <% } %>
    <br>
    Zip code: <%= zip %>
    <br>
    Area code: <%= area %>
    <br>
    Phone: <%= phone %>
    <p>
<% 	Vector<LinkedHashMap<String, Object>> degrees = (Vector<LinkedHashMap<String, Object>>)session.getAttribute("degrees");
	if(degrees != null) {
%>
<h3> Degree(s): </h3> <p>
<%	// iterate through the degree objects and list them all in html
	for ( LinkedHashMap<String, Object> deg : degrees) {
		String loc = (String)((Vector)uniTuple.get((Integer)deg.get("location"))).get(0);
	    String uni = (String)deg.get("uniName");

		// get other degree information
        String major = (String)deg.get("majorName");
		String month = (String)deg.get("month");
		String year = (String)deg.get("year");
		String gpa = (String)deg.get("gpa");
		String type = (String)deg.get("type");
%>
Location: <%= loc %> <br>
University: <%= uni %> <br>
Major: <%= major %> <br>
Expected month of graduation: <%= month %> <br>
Expected year of graduation: <%= year %> <br>
Expected GPA: <%= gpa %> <br>
Degree type: <%= type %> <br>
<p>
<% } } %>
  <h3>Please choose the location of your university: </h3> <p>
<table>
<%  String link = "degreeUni.jsp?degreeLoc=";
	String c1, c2, c3;
	int id = 0;
	//iterate through the university vector, and list them in a 3-column hyperlink format.
	Iterator it = uniTuple.iterator();
	while(it.hasNext() ) {
		c1 = (String)((Vector)it.next()).get(0);
		if(it.hasNext() ) {
			c2 = (String)((Vector)it.next()).get(0);
			if(it.hasNext() )
				c3 = (String)((Vector)it.next()).get(0);
			else
				c3 = "";
		}
		else {
			c2 = "";
			c3 = "";
		}

%>
<tr> <td> <a href="<%= link + id++ %>" > <%= c1 %> </a></td>
<td> <a href="<%= link + id++ %>" > <%= c2 %> </a> </td>
<td> <a href="<%= link + id++ %>" > <%= c3 %> </a> </td></tr>
<% } %>
</table>
  </body>
</html>
